﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SIPO.Library.DomainObject.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.UserManagement;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.DataAccess.Transaction;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DataAccess.Administration.UserManagement;
using System.Configuration;
using SIPO.Web.Support;
using System.Globalization;

namespace SIPO.Web.Forms.Transaction
{
    public partial class recReconAdjusform : BasePage
    {

        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                string Invoice = Convert.ToString(Request.Params["Invoice"]);
                hfID.Value = Invoice.ToString();



                recLoadReconDetailRepo recLoadReconDetailRepo = new recLoadReconDetailRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                recPaymentRepo recPaymentRepo = new Library.DataAccess.Transaction.recPaymentRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);

                recLoadReconDetail recLoadReconDetail = recLoadReconDetailRepo.GetByInvoiceNumber(Invoice);

                recAdjustmentTypeRepo recAdjustmentTypeRepo = new Library.DataAccess.Administration.Catalog.recAdjustmentTypeRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);

                List<recAdjustmentType> recAdjustmentTypes = recAdjustmentTypeRepo.GetList();
                ddlJenisTransaksi.Items.Clear();
                recAdjustmentTypes.ForEach(delegate(recAdjustmentType bank)
                {
                    ddlJenisTransaksi.Items.Add(new ListItem(bank.AdjustmentTypeName, bank.AdjustmentTypeID.ToString()));
                });

                ddlJenisTransaksi.Items.Insert(0, new ListItem("-- pilih tipe adjusment --", string.Empty));

                lbTglInput.Text = DateTime.Now.ToString("dd-MM-yyyy");

                GetPrivilege();
            }
        }

        private void GetPrivilege()
        {
            Membership membership = new Membership(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);

            List<recAccessRights.AccessRights> accessRights = membership.GetAccessRights(base.UserID, base.MenuID);

            accessRights.ForEach(delegate(recAccessRights.AccessRights access)
            {
                switch (access)
                {
                    case (recAccessRights.AccessRights.View):
                        ClientScript.RegisterStartupScript(typeof(Page), "view", "$('#btnSave').hide();", true);
                        break;
                    case (recAccessRights.AccessRights.Add):
                        ClientScript.RegisterStartupScript(typeof(Page), "add", "$('#btnSave').show();", true);
                        break;
                    case (recAccessRights.AccessRights.Edit):
                        ClientScript.RegisterStartupScript(typeof(Page), "edit", "$('#btnSave').show();", true);
                        break;
                    case (recAccessRights.AccessRights.NoAccess):
                        var url = Helper.GetAppVirtualPath(Page);
                        ClientScript.RegisterStartupScript(typeof(Page), "noAccess", "alert('Anda tidak mempunyai hak akses ke halaman ini!'); window.location = '" + url + "'", true);
                        break;
                }
            });

        }
    }
}